import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex'
import user from './modules/user'
import attrs from './modules/attrs'
import actions from './actions'
import mutations from './mutations'
import { State } from '../interfaces'

export const key: InjectionKey<Store<State>> = Symbol(undefined)

export const store = createStore<State>({
  state: () => {
    return { ...user, ...attrs }
  },
  actions,
  mutations
})

declare module '@vue/runtime-core' {
  // eslint-disable-next-line no-unused-vars
  interface ComponentCustomProperties {
    $store: Store<State>
  }
}

export function useStore() {
  return baseUseStore(key)
}
